package Hot100;

public class 矩阵置零 {
    public void setZeroes(int[][] matrix) {
        int colLen = matrix.length, rowLen = matrix[0].length;
        boolean flag = false;
        for (int i = 0; i < colLen; i++) {
            if (matrix[i][0] == 0) flag = true;
            for (int j = 1; j < rowLen; j++) if (matrix[i][j] == 0) matrix[0][j] = matrix[i][0] = 0;
        }
        for (int i = colLen - 1; i >= 0; i--) {
            for (int j = rowLen - 1; j >= 1; j--) if (matrix[i][0] == 0 || matrix[0][j] == 0) matrix[i][j] = 0;
            if (flag) matrix[i][0] = 0;
        }
    }
}
